package org.example.project.service.impl;

import org.example.project.dao.PlantDao;
import org.example.project.entity.IdentificationRecord;
import org.example.project.entity.Plant;
import org.example.project.entity.PopularScience;
import org.example.project.service.PlantService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author 岩
 * @Package org.example.project.service.impl
 * @Project MyApp
 * @Name PlantServiceImpl
 * @Date 2024-04-28 14:22
 * @Filename PlantServiceImpl
 */

@Service("plantService")
public class PlantServiceImpl implements PlantService {

    @Resource
    private PlantDao plantDao;
    /**
     * @return 植物列表
     */
    @Override
    public List<Plant> getAllPlants() {
        return this.plantDao.getAllPlants();
    }

    /**
     * @param plantId 植物ID
     * @return 植物信息
     */
    @Override
    public Plant getPlantById(int plantId) {
        return this.plantDao.getPlantById(plantId);
    }

    /**
     * @param plantName 植物名称
     * @return 植物列表
     */
    @Override
    public List<Plant> getPlantsByName(String plantName) {
        return this.plantDao.getPlantsByName(plantName);
    }

    /**
     * @param plant 新增植物信息
     * @return 植物信息
     */
    @Override
    public Plant addPlant(Plant plant) {
        this.plantDao.addPlant(plant);
        return this.plantDao.getPlantById(plant.getId());
    }

    /**
     * @param plantId 待删除植物ID
     * @return 删除成功与否
     */
    @Override
    public Boolean deletePlant(int plantId) {
        return this.plantDao.deletePlant(plantId) > 0;
    }

    /**
     * @param plant 待更新植物信息
     * @return 植物信息
     */
    @Override
    public Plant updatePlant(Plant plant) {
        this.plantDao.updatePlant(plant);
        return this.plantDao.getPlantById(plant.getId());
    }

    /**
     * @return 科普植物列表
     */
    @Override
    public List<Plant> getKnowledgePlants() {
        return this.plantDao.getKnowledgePlants();
    }

    /**
     * @param plantId 植物ID
     * @return 科普植物信息
     */
    @Override
    public Plant getKnowledgePlantById(int plantId) {
        return this.plantDao.getKnowledgePlantById(plantId);
    }

    /**
     * @param plantName 植物名称
     * @return 科普植物列表
     */
    @Override
    public List<Plant> getKnowledgePlantsByName(String plantName) {
        return this.plantDao.getKnowledgePlantsByName(plantName);
    }

    /**
     * @param pS 新增科普植物
     * @return 科普植物信息
     */
    @Override
    public Plant addKnowledgePlant(PopularScience pS) {
        this.plantDao.addKnowledgePlant(pS);
        return this.plantDao.getPlantById(pS.getPlantId());
    }

    /**
     * @param id 待删除科普植物ID
     * @return 删除成功与否
     */
    @Override
    public Boolean deleteKnowledgePlant(int id) {
        return this.plantDao.deleteKnowledgePlant(id) > 0;
    }

    /**
     * @param pR 识别植物
     * @return 识别记录
     */
    @Override
    public Plant addRecognitionRecord(IdentificationRecord pR) {
        this.plantDao.addRecognitionRecord(pR);
        return this.plantDao.getPlantById(pR.getPlantId());
    }

    /**
     * @param plantId 待删除识别记录的植物ID
     * @return 删除成功与否
     */
    @Override
    public Boolean deleteRecognitionRecord(int plantId) {
        return this.plantDao.deleteRecognitionRecord(plantId) > 0;
    }

    /**
     * @return 所有识别记录
     */
    @Override
    public List<Plant> getAllRecognitionRecords() {
        return this.plantDao.getAllRecognitionRecords();
    }

    /**
     * @param plantId 植物ID
     * @return 识别记录
     */
    @Override
    public Plant getRecognitionRecordById(int plantId) {
        return this.plantDao.getRecognitionRecordByPlantId(plantId);
    }

    /**
     * @param plantName 植物名称
     * @return 识别记录
     */
    @Override
    public List<Plant> getRecognitionRecordsByName(String plantName) {
        return this.plantDao.getRecognitionRecordByPlantName(plantName);
    }

    /**
     * @param userId 用户ID
     * @return 识别记录
     */
    @Override
    public List<Plant> getRecognitionRecordsByUserId(int userId) {
        return this.plantDao.getRecognitionRecordByUserId(userId);
    }


}
